<?php

namespace app\api\Logic\Pay;

use app\api\model\PayLogModel;

class PayLogic
{
    /**
     * 插入订单主表
     * @param $data
     * @return int|string
     */
    public function createOrder($data){
        //订单总表待插入数据
        $pay_data = [
            'shop_id' => $data['shop_id'] ?? 0,
            'controller' => $data['controller'] ?? '',
            'order_id' => $data['order_id'] ?? 0,
            'order_sn'=> $data['out_trade_no'] ?? '',
            'user_id' => $data['user_id'] ?? 0,
            'price' => $data['price'] ?? 0,
            'coupon_id' => $data['coupon_id'] ?? 0,
            'coupon_amount' => $data['coupon_amount'] ?? 0,
            'discount' => $data['discount'] ?? 0,
            'activity_id' => $data['activity_id'] ?? 0,
            'activity_price' => $data['activity_price'] ?? 0,
            'score' => $data['score'] ?? 0,
            'score_amount' => $data['score_amount'] ?? 0,
            'real_price' => $data['real_price'] ?? 0,
            'pay_amount' => $data['pay_amount'] ?? 0,
            'transaction_id' => $data['transaction_id'] ?? '',
            'payment_json' => $data['payment_json'] ?? '',
            'pay_type'=> $data['pay_type'] ?? 0,
            'pay_time'=> $data['pay_time'] ?? 0,
            'status'=> $data['status'] ?? 0,
            'refund_status'=> $data['refund_status'] ?? 0,
            'refund_amount'=> $data['refund_amount'] ?? 0,
            'createtime' => time()
        ];

        //插入主订单表
        return PayLogModel::insertGetId($pay_data);
    }
}
